using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;

namespace Code5Systems.FormMaster.Business
{
	
	public partial class FormController
	{
		
#region Public Enumerations
		
		//BitField used to show or hide Design Time Controls
		//based on the Control Type Selected
		[Flags()]public enum Fields
		{
			None = 0x0,
			TextMode = 0x1,
			Rows = 0x2,
			Columns = 0x4,
			MaxLength = 0x8,
			Required = 0x10,
			RegEx = 0x20,
			LabelCssClass = 0x40,
			Checked = 0x80,
			InitialValue = 0x100,
			ListItems = 0x200,
			RepeatDirection = 0x400,
			RepeatColumns = 0x800,
			Validators = 0x1000,
			HtmlEditor = 0x2000,
			TextBox = 0x4000,
			AutoFillField = 0x8000,
			FileUpload = 0x10000,
			SubmitButton = 0x20000,
			SendValueBy = 0x40000,
			FillListItem = 0x80000,
			FieldQuery = 0x100000
		}
		
		public enum MoveDirection
		{
			Up = 1,
			Right = 2,
			Down = 3,
			Left = 4,
			MoveTo = 5
		}
		
		public enum ListItemToSave
		{
			Text = 0,
			Value = 1
		}
		
		public enum AutoFillType
		{
			None = 0,
			Membership = 1,
			Session = 2,
			Url = 3,
			Cookie = 4,
			FormQuery = 5,
			FieldQuery = 6,
			ServerVariables = 7
		}
		
		public enum SendValueBy
		{
			None = 0,
			Session = 1,
			Url = 2,
			Cookie = 3,
			Post = 4,
			PostAndSession = 5,
			PostAndCookie = 6
		}
		
#endregion
		
#region Private Members
		private string _sharedResourceFile;
		private bool _hasRequredFieldValidators = false;
		private bool _hasCascadingDropdowns = false;
		//private string _validationGroup;
		private FormInfo _formInfo;
		private int _moduleId;
		private List<FieldRulesScriptInfo> _fieldRules;
		private List<FormFieldRulesInfo> _sourceFields;
		private List<FormPageInfo> _pages;
		private List<string> _targetFields;
		private FormSettings _formSettings;
		private Dictionary<string, List<string>> _pageScripts;
		private bool _saveSerializationFixups = false;
		private List<BaseValidator> _disabledValidators;
		private List<WebControl> _buttons;
#endregion
		
#region Public Constructors)
		
		public FormController(int moduleId)
		{
			
			_sharedResourceFile = Utility.GetSharedResourceFile();
			
			Guid guid = System.Guid.NewGuid();
			
			//_validationGroup = guid.ToString();
			
			_moduleId = moduleId;
			
			_disabledValidators = new List<BaseValidator>();

			_buttons = new List<WebControl>();
			
			GetFormInfo();
			
		}
#endregion
		
		private void FormCreationSetup()
		{
			if (_fieldRules == null)
			{
				//Setup the Objects needed for creating the JavaScript for the Field Rules
				FormFieldRulesController oFieldRulesCtl = new FormFieldRulesController();
				_fieldRules = new List<FieldRulesScriptInfo>();
				_sourceFields = oFieldRulesCtl.GetSourceFields(this.FormInfo.FormID);
				_targetFields = oFieldRulesCtl.GetTargetFields(this.FormInfo.FormID);
				
				//Add a FieldRuleScriptInfo for Each Rule in the Form
				foreach (FormFieldRulesInfo item in _sourceFields)
				{
					_fieldRules.Add(new FieldRulesScriptInfo(item));
				}
				
				_pageScripts = Utility.GetPageScriptsDictionary();
			}
		}
		
#region Public Properties
		
		public string SharedResouceFile
		{
			get
			{
				return _sharedResourceFile;
			}
		}

		public List<WebControl> FormButtons
		{
			get
			{
				return _buttons;
			}
		}
		
		public FormInfo FormInfo
		{
			get
			{
				return _formInfo;
			}
		}
		
		public List<FormPageInfo> Pages
		{
			get
			{
				return _pages;
			}
		}

		public bool HasCalculation { get; set; }
		public bool HasValidators { get; set; }
		
#endregion
		
	}
	
}
